package com.zhuiYun.project.api.seckill.controller;

import com.zhuiYun.project.annotation.OptLog;
import com.zhuiYun.project.api.commodity.model.CommodityModel;
import com.zhuiYun.project.api.seckill.entity.Seckill;
import com.zhuiYun.project.api.seckill.model.SeckillModel;
import com.zhuiYun.project.api.seckill.service.SeckillService;
import com.zhuiYun.project.common.controller.BaseController;
import com.zhuiYun.project.common.errorCode.CommonException;
import com.zhuiYun.project.common.response.CommonConstants;
import com.zhuiYun.project.common.response.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
  *@ClassName SeckillController
  *@Description TODO
  *Author 高
  *@Date 2023/4/11 10:15
  *@Version 1.0
**/
@RestController
@RequestMapping("/Seckill")
@Api(tags = "日志操作模块")
@Slf4j
public class SeckillController extends BaseController {
    @Autowired
    SeckillService seckillService;
    /**
     * 查询秒杀信息
     * @param
     * @return
     */
    @GetMapping("/getSeckillByPage")
    @ApiOperation(value = "秒杀的分页查询方法")
    @OptLog(modular = "秒杀信息管理", type = CommonConstants.SELECT, describe = "秒杀分页查询")
    public List<Seckill> getSeckillAndCommodity(Seckill seckill) {
        return seckillService.getSeckillByPage(seckill);
    }
    /**
     * 添加秒杀信息
     * @param
     * @return
     */
    @PostMapping("/publishSeckillAdd")
    @ApiOperation(value = "秒杀的新增方法")
    @OptLog(modular = "秒杀管理", type = CommonConstants.ADD, describe = "新增秒杀")
    public CommonResult CommodityAdd(@RequestBody Seckill seckill) throws CommonException {
        System.out.println(seckill);
        int i = seckillService.SeckillAdd(seckill);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.error("添加失败");
        }
    }
    /**
     * 修改秒杀信息
     * @param
     * @return
     */
    @PostMapping("/publishSeckillUpdate")
    @ApiOperation(value = "秒杀的修改方法")
    @OptLog(modular = "秒杀管理", type = CommonConstants.UPDATE, describe = "修改秒杀")
    public CommonResult CommodityUpdate( @RequestBody Seckill seckill) throws CommonException {
        System.out.println(seckill);
        int i = seckillService.SeckillUpdate(seckill);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.error("修改失败");
        }
    }
    /**
     * 删除用户信息
     * @param id
     * @return
     */
    @DeleteMapping("/delSeckilById")
    @ApiOperation(value = "秒杀的删除方法")
    @OptLog(modular = "用户管理", type = CommonConstants.DELETE, describe = "删除秒杀信息")
    public CommonResult delSeckillById(Integer id) throws CommonException {
        log.info("删除秒杀信息");
        return seckillService.delSeckillById(id);
    }
}